// 封装 获取权限状态
export const getSetting = ()=>{
    return new Promise ((resolve, reject)=>{
        wx.getSetting({
            success: (result)=>{
                resolve(result)
                // console.log(resolve(result));
            },
            fail: (err)=>{
                reject(err)
            },
            complete: ()=>{}
        });
    })
}

// 封装 直接获取用户收货地址
export const chooseAddress = ()=>{
    return new Promise ((resolve, reject)=>{
        wx.chooseAddress({
            success: (result)=>{
                resolve(result)
                // console.log(  resolve(result));
            },
            fail: (err)=>{
                reject(err)
            },
            complete: ()=>{}
        });
    })
}

// 封装 用户以前拒绝授予权限，要诱导用户打开授权页面
export const openSetting = ()=>{
    return new Promise ((resolve, reject)=>{
        wx.openSetting({
            success: (result)=>{
                resolve(result)
                // console.log(resolve(result));
            },
            fail: (err)=>{
                reject(err)
            },
            complete: ()=>{}
        });
    })
}

//封装删除商品提示
export const showModal = ({content})=>{
    return new Promise ((resolve, reject)=>{
        wx.showModal({
            title: '提示',
            content: content,
            success :(res) => {
              resolve(res);   
            },
            fail: (err) =>{
              reject(err);
            }
          })
    })
}

//封装弹窗提示 没有选收货地址
export const showToast = ({title})=>{
    return new Promise ((resolve, reject)=>{
        wx.showToast({
            title: title,
            icon: "none",
            success :(res) => {
              resolve(res);   
            },
            fail: (err) =>{
              reject(err);
            }
          })
    })
}

//封装获取小程序登录成功后的code
export const login = ()=>{
    return new Promise ((resolve, reject)=>{
        wx.login({
            timeout:10000,
            success: (result)=>{
                resolve(result)
            },
            fail: (err)=>{
                reject(err)
            },
        });
    })
}

//封装小程序微信支付的api功能
export const requestPayment = (pay)=>{
    return new Promise ((resolve, reject)=>{
        wx.requestPayment({
            ...pay,
            success: (result)=>{
                resolve(result);
            },
            fail: (err)=>{
                reject(err);
            },
        });
    })
}

//封装获取用户信息
export const getUserProfile = ({desc})=>{
    return new Promise ((resolve, reject)=>{
        wx.getUserProfile({
            desc:desc,
            success: (result)=>{
                resolve(result);
            },
            fail: (err)=>{
                reject(err);
            },
        });
    })
}
